package com.item.mobile;

import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.base.mobile.MobException;
import com.base.mobile.MobileInfo;
import com.base.mobile.server.annotation.Mobile;
import com.base.mobile.server.annotation.MobileMethod;
import com.base.util.StringUtil;
import com.item.dao.model.FeedBack;
import com.item.service.FeedBackService;
import com.mobile.api.proto.MSystem.MRet;

/**
 * 校车接口
 * @author yjh
 *
 */
@Component
@Mobile
public class MAppFeeback {
	@Autowired
	FeedBackService feedbackService;
	
	/**
	 * 校车时刻表
	 * @param mobileInfo
	 * @return
	 */
	@MobileMethod(methodno = "MFeedback",isLogin=false,isPage=false)
	public MRet.Builder feedback(MobileInfo mobileInfo, String content, String contact) throws Exception {
		//参数校验
		MRet.Builder ret = MRet.newBuilder();
		
		FeedBack record = new FeedBack();
		record.setContact(StringUtil.emptyIfBlank(contact));
		record.setContent(StringUtil.emptyIfBlank(content));
		record.setCreateTime(new Date());
		record.setUserid(StringUtil.emptyIfBlank(mobileInfo.getUserid()));
		
		int row = feedbackService.insertSelective(record);
		if(row > 0) {
			ret.setCode(1);
		} else {
			throw new MobException(MEnumError.FEEDBACK_INSERT_ERROR);
		}
		
		return ret;
	}
}
